<template>
  <!-- 轮播图 -->
  <el-carousel
    :interval="4000"
    type="card"
    height="35vh"
    class="carousel-container"
  >
    <el-carousel-item
      v-for="(item,index) in carouselItems"
      :key="index"
    >
      <div class="carousel-item">
        <img
          :src="item.image"
          alt="carousel"
          class="carousel-image"
        />
        <div class="carousel-text">
          <h2>{{ item.title }}</h2>
          <!-- <p>{{ item.description }}</p> -->
        </div>
      </div>
    </el-carousel-item>
  </el-carousel>

  <!-- 内容 -->
  <Transition
    name="introduce"
    appear
  >
    <div class="company-intro">
      <h2 class="intro-title">科协——以科技赋能未来，以创新引领变革</h2>
      <p class="intro-content">科学技术创新协会秉承"创新引领未来，科技服务社会"的理念，以"以赛促学、以赛促创"为核心路径，通过参与竞赛、项目孵化和学科交叉实践，全面提升成员在考研、就业、产品研发及商业转化等领域的核心能力，致力于打造具有学术深度、实践温度和社会责任感的科技创新共同体。
科学技术创新协会以协会社长为总指挥的领导方针，包含竞赛，竞赛服务，财务管理，社团规划，社团部门分配等问题以及后续的不断完善方针。
      </p>
    </div>
  </Transition>
  <!-- 产品系列 -->
  <Transition
    name="product-title"
    appear
  >
    <div class="product-series">
      <h2 class="product-title">产品系列</h2>
      <p class="product-subtitle">专业定制，打造独特产品</p>
    </div>
  </Transition>
  <div class="product-and-events">
    <!-- 文字 -->
    <Transition
      name="product-swiper"
      appear
    >
      <constmer
        :tabList="productList"
        :colorMap="productColorMap"
        class="product-swiper-component"
      ></constmer>
    </Transition>
    <!-- 事件 -->
    <Transition
      name="hot-events"
      appear
    >
      <Hotevents class="hot-events-component"></Hotevents>
    </Transition>
  </div>
</template>

<script>
import constmer from "../../components/Constmer.vue";
import Hotevents from "../../components/Hot-events.vue";
import { directive as vIntersect } from "vue-intersection-observer";

export default {
  components: {
    constmer,
    Hotevents,
  },
  directives: {
    intersect: vIntersect,
  },
  data() {
    return {
      carouselItems: [
        {
          image: require("../../assets/company/img1.jpg"),
          title: "科协",
        },
        {
          image: require("../../assets/company/img2.jpg"),
          title: "科协",
        },
        {
          image: require("../../assets/company/img3.jpg"),
          title: "科协",
        },
      ],
      productList: [
        {
          title: "ERP",
          value: "0",
          image:
            "http://www.aibang8.fun:6061/erp.jpg",
        },
        {
          title: "HRP",
          value: "1",
          image:
            "http://www.aibang8.fun:6061/hrp.png",
        },
        {
          title: "WCM",
          value: "2",
          image:
            "http://www.aibang8.fun:6061/WCM.jpg",
        },
      ],
      productColorMap: {
        0: "green",
        1: "pink",
        2: "yellow",
      },
      //视口监视
      isProductTitleVisible: false,
      isProductSwiperVisible: false,
      isHotEventsVisible: false,
    };
  },
  methods: {
    //视口监视
    onIntersectProductTitle([entry]) {
      if (entry.isIntersecting) {
        this.isProductTitleVisible = true;
      }
    },
    onIntersectProductSwiper([entry]) {
      if (entry.isIntersecting) {
        this.isProductSwiperVisible = true;
      }
      console.log(this.isProductSwiperVisible);
    },
    onIntersectHotEvents([entry]) {
      if (entry.isIntersecting) {
        this.isHotEventsVisible = true;
      }
    },
  },
};
</script>

<style scoped>
.carousel-container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 10px;
  box-sizing: border-box;
}

.carousel-item {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-align: center;
}

.carousel-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

.carousel-text {
  position: relative;
  z-index: 2;
  background: rgba(0, 0, 0, 0.5);
  padding: 15px;
  border-radius: 10px;
  width: 90%;
}

.carousel-text h2 {
  font-size: 1.2rem;
  margin: 0;
}

/* 过渡动画 */
.introduce-enter-active,
.introduce-leave-active {
  transition: transform 3s ease-out, opacity 4s ease;
}
.introduce-enter-from,
.introduce-leave-to {
  transform: translateX(-100%);
  opacity: 0;
}

.company-intro {
  margin: 20px auto;
  text-align: left;
  padding: 15px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: black;
  width: 90%;
  max-width: 1200px;
  box-sizing: border-box;
}

.intro-title {
  background: linear-gradient(to right, white, 60%, rgb(217, 215, 215));
  font-size: 1.2rem;
  padding: 10px;
  margin: 0 0 15px 0;
  border-radius: 5px;
}

.intro-content {
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: justify;
  margin: 0;
}

.product-series {
  text-align: center;
  color: black;
  width: 90%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
  box-sizing: border-box;
}

.product-title {
  font-size: 1.5rem;
  margin: 20px 0 10px 0;
  text-align: center;
}

.product-subtitle {
  font-size: 1rem;
  background: linear-gradient(to right, white, 60%, rgb(217, 215, 215));
  padding: 8px;
  border-radius: 5px;
  margin: 0 auto 20px auto;
  text-align: left;
}

.product-and-events {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 20px auto;  
  width: 100%;
  max-width: 1200px;
  /* gap: 20px; */
}

.product-swiper-component,
.hot-events-component {
  width: 40%;
}

.product-title-enter-active {
  transition: transform 3s ease-out, opacity 3s ease;
}
.product-title-enter-from {
  transform: translateY(-100%);
  opacity: 0;
}

.product-swiper-enter-active {
  transition: transform 3s ease-out, opacity 3s ease;
}
.product-swiper-enter-from {
  transform: translateX(-100%);
  opacity: 0;
}

.hot-events-enter-active {
  transition: transform 3s ease-out, opacity 3s ease;
}
.hot-events-enter-from {
  transform: translateX(100%);
  opacity: 0;
}

/* 平板设备 */
@media (min-width: 768px) {
  .carousel-text h2 {
    font-size: 1.5rem;
  }
  
  .company-intro {
    padding: 20px;
    margin: 30px auto;
  }
  
  .intro-title {
    font-size: 1.5rem;
    padding: 15px;
  }
  
  .intro-content {
    font-size: 1rem;
  }
  
  .product-title {
    font-size: 2rem;
    margin: 30px 0 15px 0;
  }
  
  .product-subtitle {
    font-size: 1.2rem;
    padding: 10px;
  }
  
  .product-and-events {
    flex-direction: row;
    justify-content: space-between;
    gap: 20px;
  }
  
  .product-swiper-component,
  .hot-events-component {
    flex: 1;
    min-width: 0; /* 防止flex项目溢出 */
    width: 0;
  }
}

/* 桌面设备 */
@media (min-width: 1024px) {
  .carousel-container {
    padding: 0 20px;
  }
  
  .carousel-text {
    padding: 20px;
    width: 80%;
  }
  
  .carousel-text h2 {
    font-size: 2rem;
  }
  
  .company-intro {
    padding: 30px;
    margin: 40px auto;
  }
  
  .intro-title {
    font-size: 1.8rem;
    padding: 20px;
  }
  
  .intro-content {
    font-size: 1.1rem;
  }
  
  .product-title {
    font-size: 2.5rem;
  }
  
  .product-subtitle {
    font-size: 1.5rem;
    padding: 15px;
  }
  
  .product-and-events {
    margin: 40px auto;
    gap: 30px;
  }
}

/* 大屏幕设备 */
@media (min-width: 1200px) {
  .carousel-text {
    width: 70%;
  }
  
  .intro-title {
    font-size: 2rem;
  }
  
  .intro-content {
    font-size: 1.2rem;
  }
  
  .product-title {
    font-size: 3rem;
  }
  
  .product-subtitle {
    font-size: 1.8rem;
  }
}

@media (max-width: 767px) {
  .carousel-container {
    height: 25vh;
    padding: 0 5px;
  }
  
  .carousel-text {
    padding: 10px;
    width: 95%;
  }
  
  .carousel-text h2 {
    font-size: 1rem;
  }
  
  .company-intro {
    padding: 10px;
    margin: 15px auto;
    width: 95%;
  }
  
  .intro-title {
    font-size: 1.1rem;
    padding: 8px;
    margin: 0 0 10px 0;
  }
  
  .intro-content {
    font-size: 0.85rem;
    line-height: 1.5;
  }
  
  .product-series {
    width: 95%;
    padding: 0 10px;
  }
  
  .product-title {
    font-size: 1.3rem;
    margin: 15px 0 8px 0;
  }
  
  .product-subtitle {
    font-size: 0.9rem;
    padding: 6px;
    margin: 0 auto 15px auto;
  }
  
  .product-and-events {
    flex-direction: column;
    gap: 15px;
    margin: 15px auto;
    width: 95%;
  }
  
  .product-swiper-component,
  .hot-events-component {
    width: 100%;
  }
  
  /* 调整过渡动画在移动端的持续时间 */
  .introduce-enter-active,
  .introduce-leave-active {
    transition: transform 1.5s ease-out, opacity 2s ease;
  }
  
  .product-title-enter-active {
    transition: transform 1.5s ease-out, opacity 1.5s ease;
  }
  
  .product-swiper-enter-active,
  .hot-events-enter-active {
    transition: transform 1.5s ease-out, opacity 1.5s ease;
  }
}

/* 超小屏幕优化 (最大宽度 400px) */
@media (max-width: 400px) {
  .carousel-container {
    height: 20vh;
  }
  
  .carousel-text h2 {
    font-size: 0.9rem;
  }
  
  .intro-title {
    font-size: 1rem;
  }
  
  .intro-content {
    font-size: 0.8rem;
  }
  
  .product-title {
    font-size: 1.1rem;
  }
  
  .product-subtitle {
    font-size: 0.8rem;
  }
}

/* 中等屏幕手机优化 (401px - 767px) */
@media (min-width: 401px) and (max-width: 767px) {
  .carousel-container {
    height: 30vh;
  }
}
</style>